<?php
//echo "<pre>";
//print_r($engineReturn['record']);
if($engineReturn['record']['mode']=='all')
{
	if($engineReturn['insert']==true)
	{
		echo "<a href='".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/normal/insert/' class='aNav' id='insert_new_div'>Insert New</a>";
	}

							if(is_array($engineReturn['record']['filterField']) && (count($engineReturn['record']['filterField'])>0))
							{
								echo "<div class='containerFilter'>";
								echo "<h3>Filter</h3>";
								echo "<table class='table'>";
								foreach($engineReturn['record']['filterField'] as $k=>$r)
								{
									echo "<tr>";
									echo "<td><b>".$r['text']."</b></td>";
									echo "<td>";
									switch($r['input'])
									{
										case "text":
											echo "<input type='text' id='filter-id-".$r['name']."' name='filter-id-".$r['name']."' class='engineInput autoinput' size='30' maxlength='100'>";
										break;
										case "radio":
											echo "<table>";
											foreach($r['source_value'] as $rs)
											{
												echo "<tr><td>";
													echo "<input type='radio' id='filter-id-".$r['name']."' name='filter-id-".$r['name']."' value='".$rs[0]."'> ".(isset($rs[1])?$rs[1]:$rs[0]);
												echo "</td></tr>";
											}
											echo "</table>";
										break;
										case "select":
											echo "<select id='filter-id-".$r['name']."' name='filter-id-".$r['name']."'>";
											echo "<option value=''>-".$r['text']."-</option>";
											foreach($r['source_value'] as $rs)
											{
													echo "<option value='".$rs[0]."'> ".(isset($rs[1])?$rs[1]:$rs[0])."</option>";
											}
											echo "</select>";
										break;
										case "simple_table":
											echo "<select id='filter-id-".$r['name']."' name='filter-id-".$r['name']."'>";
											echo "<option value=''>--</option>";
											foreach($r['source_value'] as $rs)
											{
													echo "<option value='".$rs['idRec']."'> ".$rs['dataRec']."</option>";
											}
											echo "</select>";
										break;
										case "medium_table":
//										echo "medium";
//											echo "<pre>";
//											print_r($r);
											echo "<input type='hidden' id='filter-id-".$r['name']."' name='filter-id-".$r['name']."' value=''>";
											echo "<div  id='container-".$r['name']."' name='container-".$r['name']."' class='engineInputContainer'>";
												echo "<div id='edit-".$r['name']."' name='edit-".$r['name']."' class='defContainer' title='Press here to switch beetwen Search and View Mode'>";
													echo "<a href='#' class='engineInputEdit' id='edit-button-".$r['name']."' name='edit-button-".$r['name']."'>Edit</a>";
												echo "</div>";
						
												echo "<div id='search-".$r['name']."' name='search-".$r['name']."' class='defContainer' style='display:none;'>";
													echo "<input type='text' id='search-input-".$r['name']."' name='search-input-".$r['name']."' class='rejectInput engineInput' size='' maxlength=''>";
													echo "<div id='ajax-".$r['name']."' name='ajax-".$r['name']."' class='containerAjax'></div>";
												echo "</div>";
						
												echo "<div  id='view-".$r['name']."' name='view-".$r['name']."' class='engineInputView'>";
												echo "</div>";
											echo "</div>";
											echo "<script type='text/javascript'>";
											echo "$(document).ready(function(){";
											echo "$('#edit-button-".$r['name']."').loadMediumTable({
											module_name 		: 'filter-id-".$r['name']."'
											, search_div_id 	: 'search-".$r['name']."'
											, search_input_id 	: 'search-input-".$r['name']."'
											, view_div_id		: 'view-".$r['name']."'
											, ajax_div_id		: 'ajax-".$r['name']."'
											, url				: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/medium_table/".$r['name']."/'});";
											echo "});";
											echo "</script>";


										break;
										case "advance_table":
//										echo "advance";
//											echo "<pre>";
//											print_r($r);
											echo "<input type='hidden' id='filter-id-".$r['name']."' name='filter-id-".$r['name']."' value=''>";
											echo "<div  id='container-".$r['name']."' name='container-".$r['name']."' class='engineInputContainer'>";
												echo "<div id='edit-".$r['name']."' name='edit-".$r['name']."' class='defContainer'>";
													echo "<a href='#' class='engineInputEdit' id='edit-button-".$r['name']."' name='edit-button-".$r['name']."' title='Press here to switch beetwen Search and View Mode'>Edit</a>";
												echo "</div>";
						
												echo "<div id='search-".$r['name']."' name='search-".$r['name']."' class='defContainer' style='display:none;'>";
													echo "<input type='text' id='search-input-".$r['name']."' name='search-input-".$r['name']."' class='rejectInput engineInput' size='' maxlength=''>";
													echo "<div id='ajax-".$r['name']."' name='ajax-".$r['name']."' class='containerAjax'></div>";
												echo "</div>";
						
												echo "<div  id='view-".$r['name']."' name='view-".$r['name']."' class='engineInputView'>";
												echo "</div>";
											echo "</div>";
											echo "<script type='text/javascript'>";
											echo "$(document).ready(function(){";
											echo "$('#edit-button-".$r['name']."').loadAdvanceTable({
											module_name 		: 'filter-id-".$r['name']."'
											, search_div_id 	: 'search-".$r['name']."'
											, search_input_id 	: 'search-input-".$r['name']."'
											, view_div_id		: 'view-".$r['name']."'
											, ajax_div_id		: 'ajax-".$r['name']."'
											, filter_div_id 	: 'filter-".$r['name']."'
											, url				: '".$baseUrlSave.$otority."/engine/".$engineReturn['modulename']."/ajax/advance_table/".$r['name']."/'});";
											echo "});";
											echo "</script>";


										break;
									}
									echo "</td>";
								}
								echo "</table>";
								echo "</div>";
								
//								echo "<a href='' class='aNav' id='filter_view_data'>Filter</a>";
							}


	echo "<div id='containerGrid'>";
	$this->load->view("engine/module/grid.php", array("engineReturn"=>$engineReturn));
	echo "</div>";
}
elseif($engineReturn['record']['mode']=='data')
{
	$this->load->view("engine/module/grid.php", array("engineReturn"=>$engineReturn));
}
elseif($engineReturn['record']['mode']=='print')
{
	$this->load->view("engine/module/print.php", array("engineReturn"=>$engineReturn));
}
?>
<script type="text/javascript">
/*
	$('#insert_new_div').navigateToInsertData({
		url 			: '<?php echo $baseUrlSave;?>admin/engine/<?php echo $engineReturn['modulename'] ?>/ajax/insert/',
		div_loading 	: 'ajaxLoading',
		div_grid		: 'ajaxGrid',
		div_container	: 'insert_new_div',
		});
	$('.autoinput').navigateViewData({
		url 			: '<?php echo $baseUrlSave;?><?php echo $otority;?>/engine/<?php echo $engineReturn['modulename'] ?>/ajax/view/data/10/1/',
		div_loading 	: 'ajaxLoading',
		div_grid		: 'ajaxGrid',
		div_container 	: 'containerGrid',
		autocomplete	: true,
		field_filter	: {
			<?php
			$num = 0;
			if(is_array($engineReturn['record']['filterField']))
			foreach($engineReturn['record']['filterField'] as $key=>$row)
			{
				echo $num." : {0:'".$row['name']."', 1:'".$engineReturn['record']['filterField'][$key]['input']."'}, \n";
				$num++;
			}
			?>
			},
		len_filter	: '<?php
			if(is_array($engineReturn['record']['filterField']))
				echo count($engineReturn['record']['filterField']);
			else
				echo 0;
			?>'
		});
*/

</script>